home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Festival Card Factory
/
Festival Card Factory.iso
/
graphwin.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-12-25
|
11KB
|
405 lines
unit GraphWin;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, StdCtrls, Buttons, ColorGrd, Menus, Printers, ClipBrd, Dialogs,
ExtCtrls;
type
TDrawingTool = (dtLine, dtRectangle, dtEllipse, dtRoundRect);
TForm1 = class(TForm)
ToolBar: TPanel;
LineButton: TSpeedButton;
RectangleButton: TSpeedButton;
EllipseButton: TSpeedButton;
RoundRectButton: TSpeedButton;
PenButton: TSpeedButton;
BrushButton: TSpeedButton;
PenBar: TPanel;
BrushBar: TPanel;
SolidPen: TSpeedButton;
DashPen: TSpeedButton;
DotPen: TSpeedButton;
DashDotPen: TSpeedButton;
DashDotDotPen: TSpeedButton;
ClearPen: TSpeedButton;
SolidBrush: TSpeedButton;
ClearBrush: TSpeedButton;
HorizontalBrush: TSpeedButton;
VerticalBrush: TSpeedButton;
FDiagonalBrush: TSpeedButton;
BDiagonalBrush: TSpeedButton;
CrossBrush: TSpeedButton;
DiagCrossBrush: TSpeedButton;
PenColor: TColorGrid;
BrushColor: TColorGrid;
PenWidth: TScrollBar;
PenSize: TLabel;
StatusBar: TPanel;
OriginPanel: TPanel;
CurrentPanel: TPanel;
ScrollBox1: TScrollBox;
Image: TImage;
MainMenu1: TMainMenu;
File1: TMenuItem;
New1: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
Saveas1: TMenuItem;
Print1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
Edit1: TMenuItem;
Copy1: TMenuItem;
Paste1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Cut1: TMenuItem;
SpeedButton1: TSpeedButton;
Label1: TLabel;
Edit2: TEdit;
paint: TSpeedButton;
procedure LineButtonClick(Sender: TObject);
procedure RectangleButtonClick(Sender: TObject);
procedure EllipseButtonClick(Sender: TObject);
procedure RoundRectButtonClick(Sender: TObject);
procedure IMAGEMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PenButtonClick(Sender: TObject);
procedure BrushButtonClick(Sender: TObject);
procedure PenWidthChange(Sender: TObject);
procedure SetPenStyle(Sender: TObject);
procedure PenColorClick(Sender: TObject);
procedure SetBrushStyle(Sender: TObject);
procedure BrushColorClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Print1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Saveas1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure Cut1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure paintClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Drawing: Boolean;
Origin, MovePt: TPoint;
DrawingTool: TDrawingTool;
CurrentFile: string;
procedure DrawShape(TopLeft, BottomRight: TPoint; AMode: TPenMode);
end;
var
Form1: TForm1;
writ:Boolean;
bX,BY:INTEGER;
implementation
uses BMPDlg;
{$R *.DFM}
procedure TForm1.LineButtonClick(Sender: TObject);
begin
DrawingTool := dtLine;
end;
procedure TForm1.RectangleButtonClick(Sender: TObject);
begin
DrawingTool := dtRectangle;
end;
procedure TForm1.EllipseButtonClick(Sender: TObject);
begin
DrawingTool := dtEllipse;
end;
procedure TForm1.RoundRectButtonClick(Sender: TObject);
begin
DrawingTool := dtRoundRect;
end;
procedure TForm1.DrawShape(TopLeft, BottomRight: TPoint; AMode: TPenMode);
begin
with Image.Canvas do
begin
Pen.Mode := AMode;
case DrawingTool of
dtLine: begin
MoveTo(TopLeft.X, TopLeft.Y);
LineTo(BottomRight.X, BottomRight.Y);
end;
dtRectangle: Rectangle(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
dtEllipse: Ellipse(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
dtRoundRect: RoundRect(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y,
(TopLeft.X - BottomRight.X) div 2, (TopLeft.Y - BottomRight.Y) div 2);
end;
end;
end;
procedure TForm1.IMAGEMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begiN
if writ then
begin
if edit2.text<>'' then
BEGIN
image.canvas.textout(Bx,by-4,edit2.text);
EDIT2.TEXT:='';
END;
edit2.left:=x;
Edit2.top:=y+34;
Edit2.visible:=true;
activecontrol:=Edit2;
bX:=X;
BY:=Y;
end;
If paint.Down=True then
begin
Image.Canvas.Brush.Color:=BrushColor.ForegroundColor;
Image.Canvas.FloodFill(x,y,clBlack,fsBorder);
end
else
begin
Drawing := True;
Image.Canvas.MoveTo(X, Y);
Origin := Point(X, Y);
MovePt := Origin;
OriginPanel.Caption := Format('Origin: (%d, %d)', [X, Y]);
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Drawing then
DrawShape(Origin, Point(X, Y), pmCopy);
Drawing := False;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing then
begin
DrawShape(Origin, MovePt, pmNotXor);
MovePt := Point(X, Y);
DrawShape(Origin, MovePt, pmNotXor);
end;
CurrentPanel.Caption := Format('Current: (%d, %d)', [X, Y]);
end;
procedure TForm1.PenButtonClick(Sender: TObject);
begin
PenBar.Visible := PenButton.Down;
end;
procedure TForm1.BrushButtonClick(Sender: TObject);
begin
BrushBar.Visible := BrushButton.Down;
end;
procedure TForm1.PenWidthChange(Sender: TObject);
begin
Image.Canvas.Pen.Width := PenWidth.Position;
PenSize.Caption := IntToStr(PenWidth.Position);
end;
procedure TForm1.SetPenStyle(Sender: TObject);
begin
with Image.Canvas.Pen do
begin
if Sender = SolidPen then Style := psSolid
else if Sender = DashPen then Style := psDash
else if Sender = DotPen then Style := psDot
else if Sender = DashDotPen then Style := psDashDot
else if Sender = DashDotDotPen then Style := psDashDotDot
else if Sender = ClearPen then Style := psClear;
end;
end;
procedure TForm1.PenColorClick(Sender: TObject);
begin
Image.Canvas.Pen.Color := PenColor.ForegroundColor;
end;
procedure TForm1.SetBrushStyle(Sender: TObject);
begin
with Image.Canvas.Brush do
begin
if Sender = SolidBrush then Style := bsSolid
else if Sender = ClearBrush then Style := bsClear
else if Sender = HorizontalBrush then Style := bsHorizontal
else if Sender = VerticalBrush then Style := bsVertical
else if Sender = FDiagonalBrush then Style := bsFDiagonal
else if Sender = BDiagonalBrush then Style := bsBDiagonal
else if Sender = CrossBrush then Style := bsCross
else if Sender = DiagCrossBrush then Style := bsDiagCross;
end;
end;
procedure TForm1.BrushColorClick(Sender: TObject);
begin
Image.Canvas.Brush.Color := BrushColor.ForegroundColor;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
Bitmap.Width := form1.width-20;
Bitmap.Height := form1.height-40;
Image.Picture.Graphic := Bitmap;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Print1Click(Sender: TObject);
begin
with Printer do
begin
BeginDoc;
Canvas.Draw(0, 0, Image.Picture.Graphic);
EndDoc;
end;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
CurrentFile := OpenDialog1.FileName;
Image.Picture.LoadFromFile(CurrentFile);
end;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
if CurrentFile <> '' then
Image.Picture.SaveToFile(CurrentFile)
else SaveAs1Click(Sender);
end;
procedure TForm1.Saveas1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
CurrentFile := SaveDialog1.FileName;
Save1Click(Sender);
end;
end;
procedure TForm1.New1Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
with NewBMPForm do
begin
ActiveControl := WidthEdit;
WidthEdit.Text := IntToStr(Image.Picture.Graphic.Width);
HeightEdit.Text := IntToStr(Image.Picture.Graphic.Height);
if ShowModal <> idCancel then
begin
Bitmap := TBitmap.Create;
Bitmap.Width := StrToInt(WidthEdit.Text);
Bitmap.Height := StrToInt(HeightEdit.Text);
Image.Picture.Graphic := Bitmap;
CurrentFile := '';
end;
end;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
Clipboard.Assign(Image.Picture);
end;
procedure TForm1.Paste1Click(Sender: TObject);
var
Bitmap: TBitmap;
begin
if Clipboard.HasFormat(CF_BITMAP) then
begin
Bitmap := TBitmap.Create;
try
Bitmap.Assign(Clipboard);
Image.Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
end;
end;
procedure TForm1.Cut1Click(Sender: TObject);
var
ARect: TRect;
begin
Copy1Click(Sender);
with Image.Canvas do
begin
CopyMode := cmWhiteness;
ARect := Rect(0, 0, Image.Width, Image.Height);
CopyRect(ARect, Image.Canvas, ARect);
CopyMode := cmSrcCopy;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if Speedbutton1.down then
begin
image.cursor:=criBeam;
writ:=true;
end
else
begin
if edit2.text<>'' then
IMAGE.canvas.textout(BX,BY,edit2.text);
EDIT2.TEXT:='';
edit2.visible:=false;
writ:=false;
image.cursor:=crDefault;
end;
end;
procedure TForm1.paintClick(Sender: TObject);
begin
If paint.Down=true then
begin
image.cursor:=crMultiDrag;
penButton.Enabled:=False;
PenBar.Visible:=False;
BrushButton.Enabled:=false;
BrushBar.Visible:=true;
end
else
If paint.Down=false then
begin
image.cursor:=crDefault;
PenButton.Enabled:=true;
PenBar.Visible:=PenButton.Down;
BrushButton.Enabled:=true;
BrushBar.Visible:=brushButton.Down;
end;
end;
end.